home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / hotjava / classsrc / browser / anchor~1.jav < prev    next >
Encoding:
Text File  |  1995-08-11  |  1.9 KB  |  70 lines

  1. /*
  2.  * @(#)AnchorTagRef.java    1.8 95/03/14 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package browser;
  21.  
  22. import java.util.*;
  23. import java.io.*;
  24. import awt.*;
  25. import net.*;
  26. import net.www.http.*;
  27. import net.www.html.*;
  28.  
  29. /**
  30.  * An instance of class AnchorTagRef is created for each occurrence
  31.  * of <a ...> tags in an html document.  An AnchorTagRef is either
  32.  * an anchor (i.e., it points to another document) or it's an endpoint
  33.  * for some other document (i.e., it has no "href" attribute).
  34.  * @version 1.8, 14 Mar 1995
  35.  * @author Jonathan Payne
  36.  */
  37.  
  38. public class AnchorTagRef extends StyleTagRef {
  39.     final int    UNKNOWN = 0;
  40.     final int    ISANCHOR = 1;
  41.     final int    NOTANCHOR = 2;
  42.  
  43.     int    anchorState = UNKNOWN;
  44.  
  45.     public AnchorTagRef(Tag t, int pos, boolean isEnd, Style s) {
  46.     super(t, pos, isEnd, s);
  47.     }
  48.  
  49.     public void apply(WRFormatter f) {
  50.     if (!isEnd) {
  51.         if (anchorState == UNKNOWN) {
  52.         if (getAttribute("href") != null) {
  53.             anchorState = ISANCHOR;
  54.         } else {
  55.             anchorState = NOTANCHOR;
  56.         }
  57.         }
  58.     }
  59.     super.apply(f);
  60.     }
  61.  
  62.     /**
  63.      * Returns true if this anchor contains a link to another
  64.      * document.
  65.      */
  66.     public boolean isLink() {
  67.     return anchorState == ISANCHOR;
  68.     }
  69. }
  70.